//
//  LMOriginalView.m
//  李明微博
//
//  Created by apple on 15/12/16.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMOriginalView.h"

#import "CZStatus.h"
#import "LMStatusFrame.h"
#import "UIImageView+WebCache.h"



@interface LMOriginalView()

@property (nonatomic,weak) UIImageView *iconView;

@property (nonatomic,weak) UILabel *nameView;

@property (nonatomic,weak) UILabel *timeView;

@property (nonatomic,weak) UIImageView *vipView;

@property (nonatomic,weak) UILabel *sourceView;

@property (nonatomic,weak) UILabel *textView;


@end
@implementation LMOriginalView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame] ) {
             [self setUpAllchildView];
    }
    return self;
}

- (void)setUpAllchildView
{
    UIImageView *iconView = [[UIImageView alloc] init];
    [self addSubview:iconView];
    _iconView = iconView;
    
    UILabel *nameView = [[UILabel alloc] init];
    nameView.font = [UIFont systemFontOfSize:13];
    [self addSubview:nameView];
    _nameView = nameView;
    
    
    UILabel *timeView = [[UILabel alloc] init];
      timeView.font = [UIFont systemFontOfSize:11];
    [self addSubview:timeView];
    _timeView = timeView;
    
    UIImageView *vipView = [[UIImageView alloc] init];
    [self addSubview:vipView];
    _vipView = vipView;
    
    UILabel *sourceView = [[UILabel alloc] init];
    sourceView.font = [UIFont systemFontOfSize:11];
    [self addSubview:sourceView];
    _sourceView = sourceView;
    
    UILabel *textView = [[UILabel alloc] init];
    textView.font = [UIFont systemFontOfSize:13];
    textView.numberOfLines = 0;
    [self addSubview:textView];
    _textView = textView;
}

-(void)setStatusFrame:(LMStatusFrame *)statusFrame
{
    _statusFrame = statusFrame;
    
    [self setUpFrame];
    
    [self setUpData];
}

-(void)setUpData
{
    CZStatus *status = _statusFrame.status;
    [_iconView sd_setImageWithURL:status.user.profile_image_url placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    
    
     _nameView.text = status.user.name;
    if (status.user.vip) {
        _nameView.textColor = [UIColor redColor];
    }
    else
    {
        _nameView.textColor = [UIColor blueColor];
    }
    NSString *imageName = [NSString stringWithFormat:@"common_icon_membership_level%d",status.user.mbrank];
    _vipView.image = [UIImage imageNamed:imageName];
    
    
    _sourceView.text = status.source;
    
    _timeView.text = status.created_at;
    
    _textView.text = status.text;
    
    
    
}

-(void)setUpFrame
{
    _iconView.frame = _statusFrame.originalIconFrame;
    
    _nameView.frame = _statusFrame.originalNameFrame;
    
    if (_statusFrame.status.user.vip)
    {
        _vipView.hidden = NO;
        _vipView.frame = _statusFrame.originalVipFrame;
    }
    else
    {
         _vipView.hidden = YES;
    }
    
//    _timeView.frame = _statusFrame.originalTimeFrame;
    
    CZStatus *status = _statusFrame.status;
    CGFloat timeX = _nameView.frame.origin.x;
    CGFloat timeY = CGRectGetMaxY(_nameView.frame) + 5;
    CGSize timeSize = [status.created_at sizeWithFont:[UIFont systemFontOfSize:10]];
    _timeView.frame = (CGRect){{timeX,timeY},timeSize};
    
    
    
    _sourceView.frame = _statusFrame.originalSourceFrame;
    
    _textView.frame = _statusFrame.originalTextFrame;
}

@end
